package com.examination.mlib.baseold;
import android.content.pm.ActivityInfo;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.os.Build;
import android.os.Bundle;
import android.view.Window;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

import crossoverone.statuslib.StatusUtil;
import com.alibaba.android.arouter.launcher.ARouter;
import com.examination.mlib.R;
import com.examination.mlib.constants.ARouterConstants;
import com.examination.mlib.interfaceapi.BaiduApi;
import com.yilijk.base.utils.ActivityManagerUtils;
import com.zzhoujay.richtext.RichText;


public
 abstract  class ModuleBaseActivity extends AppCompatActivity implements IActivity {

    private BaiduApi baiduApi;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        ActivityManagerUtils.addActivities(this);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        if (savedInstanceState != null && true) {
            //重建时清除 fragment的状态
            savedInstanceState.remove("android:support:fragments");
        }
        super.onCreate(savedInstanceState);
        setContentView(bondLayout());
        //沉浸式布局
        if (Build.VERSION.SDK_INT >= 21) {
          StatusUtil.setUseStatusBarColor( this,getResources().getColor(R.color.new_theme));
          StatusUtil.setSystemStatus(this,false,false);
        }

        //设置activity 禁止横屏
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
        ARouter.getInstance().inject(this);
        //第一次设置缓存位置
        RichText.initCacheDir(this);

        //ButterKnife
//        ButterKnife.bind(this);
        baiduApi = (BaiduApi) ARouter.getInstance().build(ARouterConstants.BaiduImpl).navigation();
        initView();
        initData();
        initEvent();
    }

    @Override
    protected void onSaveInstanceState(Bundle outState) {
        super.onSaveInstanceState(outState);
        if (outState != null && true) {
            //销毁时不保存fragment的状态
            outState.remove("android:support:fragments");
        }
    }

    @Override
    protected void onStart() {
        baiduApi.onPageStart(this,this.getClass().toString());
        super.onStart();
    }

    @Override
    protected void onDestroy() {
        RichText.recycle();
        ActivityManagerUtils.removeActivities(this);
        baiduApi.onPageEnd(this,this.getClass().toString());
        super.onDestroy();
    }

    @Override
    protected void onResume() {
        baiduApi.onResume(this);
        super.onResume();
    }

    @Override
    protected void onPause() {
        baiduApi.onPause(this);
        super.onPause();
    }

    @Override
    public void finish() {
        super.finish();
    }

    @Override
    public Resources getResources() {
        Resources resources = super.getResources();
        Configuration configuration = new Configuration();
        configuration.setToDefaults();
        resources.updateConfiguration(configuration, resources.getDisplayMetrics());
        return resources;
    }

    @Override
    public void onConfigurationChanged(Configuration newConfig) {
        getResources();
        super.onConfigurationChanged(newConfig);
    }

    public void setStatusBgColor(int color){
            StatusUtil.setUseStatusBarColor( this,getResources().getColor(color));
    }


    public void setStatusTextColor(boolean isBlack,boolean isTeansparent){
            StatusUtil.setSystemStatus(this,isTeansparent,isBlack);
    }


}
interface IActivity {
    int bondLayout();
    void initView();
    void initData();
    void initEvent();
}

